package com.exporter.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

public class ComboboxSelectionListener implements ActionListener
{
    JComboBox comboExportFromDate;
    JComboBox comboToDate;

    public ComboboxSelectionListener(JComboBox comboExportFromDate, JComboBox comboToDate)
    {
        this.comboExportFromDate = comboExportFromDate;
        this.comboToDate = comboToDate;
    }

    @Override
    public void actionPerformed(ActionEvent ae)
    {
        if ( ae.getSource() == comboExportFromDate )
        {
            String fromDate = (String) comboExportFromDate.getSelectedItem();
            List< String > allDates = new ArrayList< String >();
            for ( int i = 0; i < comboExportFromDate.getItemCount(); i++ )
            {
                allDates.add( (String) comboExportFromDate.getItemAt( i ) );
            }
            while(allDates.get( 0 )!=fromDate)
            {
                allDates.remove( 0 );
            }
            String[] ascDateArr = new String[allDates.size()];
            for(int i=0;i<ascDateArr.length;i++)
            {
                ascDateArr[i] = allDates.get( i );
            }       
            ComboBoxModel comboFileToDateModel =   new DefaultComboBoxModel(ascDateArr);
            comboToDate.setModel( comboFileToDateModel );

        }
    }

}
